package jp.sourceforge.akjrcp.ui;

import java.io.File;

import jp.sourceforge.akjrcp.util.ProgressMonitorUtils;

import org.eclipse.core.runtime.IProgressMonitor;

public class FileSizeProgressMonitor extends Thread{
private int waitTime=5000;
private long maxFileSize;
private boolean cancel;
private int maxStep=100;
private int lastStep;

private String label="";
private File file;
private IProgressMonitor progressMonitor;
public void run(){
	//log.infos("tart:");
	ProgressMonitorUtils.beginMonitor(progressMonitor,label, maxStep, true);
	while(cancel==false){
	
	
	try {
		//log.infowait:");
		Thread.sleep(waitTime);
	} catch (InterruptedException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
	if(file.exists() && file.length()>0){
	int currentStep=(int) (file.length()*maxStep/maxFileSize);
	if(currentStep!=lastStep){
		int nowstep=currentStep-lastStep;
		lastStep=currentStep;
		if(currentStep==100){
			break;
		}else{
		//	log.info(currentStep);
			ProgressMonitorUtils.workedMonitor(progressMonitor,nowstep,true);
		}
		}
	}
	}
	//log.info("done:progress");
	ProgressMonitorUtils.doneMonitor(progressMonitor,true);
}
public boolean isCancel() {
	return cancel;
}
public void setCancel(boolean cancel) {
	this.cancel = cancel;
}
public File getFile() {
	return file;
}
public void setFile(File file) {
	this.file = file;
}
public String getLabel() {
	return label;
}
public void setLabel(String label) {
	this.label = label;
}
public int getLastStep() {
	return lastStep;
}
public void setLastStep(int lastStep) {
	this.lastStep = lastStep;
}
public long getMaxFileSize() {
	return maxFileSize;
}
public void setMaxFileSize(long maxFileSize) {
	this.maxFileSize = maxFileSize;
}
public int getMaxStep() {
	return maxStep;
}
public void setMaxStep(int maxStep) {
	this.maxStep = maxStep;
}
public int getWaitTime() {
	return waitTime;
}
public void setWaitTime(int waitTime) {
	this.waitTime = waitTime;
}
public IProgressMonitor getProgressMonitor() {
	return progressMonitor;
}
public void setProgressMonitor(IProgressMonitor progressMonitor) {
	this.progressMonitor = progressMonitor;
}
}
